package com.biqee.action.juhuasuan;

import java.util.List;

import org.apache.log4j.Logger;

import com.biqee.action.base.BaseAction;
import com.biqee.service.bq.BqTuanService;
import com.biqee.service.juhuasuan.JuHuaSuanParseService;

public class JuHuaSuanParseAction extends BaseAction {
	private static final Logger logger = Logger.getLogger(JuHuaSuanParseAction.class);
	
	private static final long serialVersionUID = 5751722700064115483L;

	private static final long SLEEP_INTERVAL = 2000;
	
	private JuHuaSuanParseService juHuaSuanParseService;

	public void setJuHuaSuanParseService(JuHuaSuanParseService juHuaSuanParseService) {
		this.juHuaSuanParseService = juHuaSuanParseService;
	}

	public BqTuanService bqTuanService;
	
	public void setBqTuanService(BqTuanService bqTuanService) {
		this.bqTuanService = bqTuanService;
	}

	public String parseToday() {
		juHuaSuanParseService.parseTodayData();		
		return "home";
	}
	
	public String parseStatus() {
		List<String> itemIds = bqTuanService.listAllUnExpiredJuHuaSuanItemIds();
		for(String itemId : itemIds) {
			juHuaSuanParseService.parseStatusByItemId(itemId);
			try {
				Thread.sleep(SLEEP_INTERVAL);
			} catch (InterruptedException e) {
				logger.error("interrupted. exist");
				break;
			}
		}

		return "home";
	}
	
}
